#define _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
using namespace std;



struct TreeNode {
    int val;   
    struct TreeNode* left;
    struct TreeNode* right;
    TreeNode(int x) :
        val(x), left(NULL), right(NULL) {
    }
};

class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot)
    {
        TreeNode* head = pRoot;
        vector<vector<int> > vv;

        if (!pRoot) return vv;
        queue<TreeNode*> temp;
        temp.push(head);
        TreeNode* p;
        while (!temp.empty())
        {
            vector<int> v;
            int n = temp.size();
            while (n--)
            {
                p = temp.front();
                temp.pop();
                v.push_back(p->val);
                if (p->left) temp.push(p->left);
                if (p->right) temp.push(p->right);
            }
            vv.push_back(v);
        }

        return vv;
    }

};